// pages/index/coupon.js
Page({

  data: {
    order:1,
    color:1,
    number:1,
    nocoupon:[],
    numberobj:[],coupon:[],guoqicoupon:[], spec_id:'',statu:'',
    goods_id:'',
    store_id:'',
    page:'',
    number1:''
  },
  onLoad: function (options) {
     
     this.setData({
       statu:options.statu,
       spec_id:options.spec_id,
       goods_id:options.goods_id,
       store_id:options.store_id,
       page:options.page,
       number1:options.number

     })
    this.getcoupon(1)
  

  },

  

  //滑块
  slider(e){
    console.log(e);
    
       this.setData({
         color:parseInt(e.currentTarget.dataset.order)
       })
      var order = e.currentTarget.dataset.order;
      if(this.data.order == order){
         return false;
       }else{
         var dong = 0;
         dong = (order-1)*33.33;
         dong = dong+'%';
         // console.log(order);
       }
       this.setData({
         
        order:e.currentTarget.dataset.order,
      })

       var animation = wx.createAnimation({
         duration: 200,
         timingFunction: 'ease',
       });
       
       var width= wx.getSystemInfoSync().windowWidth;
       width = (width/3)*(order-1);
       // return false;
       animation.translate(width,0).step()
       this.setData({
         ani:animation.export()
       })
       this.getcoupon(e.currentTarget.dataset.order)
  },
  getcoupon(type){
      const uid=wx.getStorageSync('uid')
       
     wx.request({
       url: 'https://zujieba.com/Api/coupon/index.html',
       data:{type:type,uid},
       method:"POST",
       success:(res)=>{
         if(type==1){
         console.log(res);
         let nocoupon=res.data.data.coupon || 0
         let numberobj=res.data.data.number
         this.setData({nocoupon,numberobj})
         }else if(type==2){
          console.log(res);
          if(res.data.success==2){
              return
          }else{
            this.setData({coupon:res.data.data.coupon})
          }
          

         }else{
           console.log(res);
           
         let  guoqicoupon=res.data.data.coupon
         this.setData({guoqicoupon})
         }
         
       }

     })
  },
  lijiclick(e){
    if(this.data.statu==1){return}
     let coupon_id=e.currentTarget.dataset.id
     let man=e.currentTarget.dataset.man
     let jian=e.currentTarget.dataset.jian
     let  spec_id=this.data.spec_id
    let goods_id=this.data.goods_id
    let  store_id=this.data.store_id
    let page=this.data.page
    let number=this.data.number1
    let uid=wx.getStorageSync('uid')
    const params={coupon_id,spec_id,goods_id,store_id,page,number,uid}
      wx.request({
        url: 'https://zujieba.com/Api/spec/coupon.html',
        data:params,
        method:"POST",
        success:(res)=>{
          console.log(params);
          
        if(res.data.success==1){
          var pages = getCurrentPages()   
          　　 var currentPage = pages[pages.length - 1] 
          　　var prevPage = pages[pages.length - 2]    
          　　
          　　prevPage.setData({
          　　　　man:man,jian:jian ,coupon_id:coupon_id })
          wx.showToast({
            title: res.data.tips,
            icon: 'success'
          })
          wx.navigateBack({
            delta: 1
          });
        }else{
          console.log(res);
          
          wx.showToast({
            title: res.data.tips,
            icon: 'none'
          })
        }
          
        }
      })
  },
  navyouhuijuan(){
    wx.navigateTo({
      url: '/pages/mine/youhuijuan/youhuijuan',
    })
  }


})